package com.bqtv.sport.ui.match.fragment

import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.viewbinding.ViewBinding
import com.bqtv.sport.adapter.MatchDetailAdapter
import com.bqtv.sport.adapter.MatchTitleAdapter
import com.bqtv.sport.app.AppActivity
import com.bqtv.sport.app.AppFragment
import com.bqtv.sport.commen.widget.LinearItemDecoration
import com.bqtv.sport.databinding.FragmentMatchAuthorBinding
import com.bqtv.sport.ui.match.MatchDateActivity


class MatchAuthorFragment : AppFragment<FragmentMatchAuthorBinding, AppActivity<ViewBinding>>() {
    private lateinit var titleAdapter: MatchTitleAdapter
    private lateinit var detailAdapter: MatchDetailAdapter

    companion object {
        private const val INTENT_KEY_TYPE = "type"
        fun newInstance(): MatchAuthorFragment {
            val fragment = MatchAuthorFragment()
            val bundle = Bundle()
            fragment.arguments = bundle
            return fragment
        }

        fun newInstance(type: String?): MatchAuthorFragment {
            val fragment = MatchAuthorFragment()
            val bundle = Bundle()
            bundle.putString(INTENT_KEY_TYPE, type)
            fragment.arguments = bundle
            return fragment
        }
    }

    override fun getViewBinding() = FragmentMatchAuthorBinding.inflate(layoutInflater)

    override fun initView() {
        binding.llNoData.visibility = View.GONE
        binding.rcvMatch.visibility = View.VISIBLE

        binding.rcvTitle.layoutManager =
            LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)
        binding.rcvTitle.addItemDecoration(
            LinearItemDecoration(
                getContext(),
                LinearItemDecoration.LineDrawMode.HORIZONTAL,
                0f,
                10f,
                10f
            )
        )
        titleAdapter = MatchTitleAdapter()
        binding.rcvTitle.adapter = titleAdapter

        binding.rcvMatch.layoutManager=LinearLayoutManager(requireContext())
        detailAdapter= MatchDetailAdapter()
        binding.rcvMatch.adapter=detailAdapter
    }

    override fun initData() {
        var list = arrayListOf<String>("全部", "推荐", "关注", "视频", "图片", "直播")
        titleAdapter.submitList(list)
        detailAdapter.submitList(list)

        binding.ivDate.setOnClickListener {
            MatchDateActivity.start(getAttachActivity()!!, object : MatchDateActivity.OnScanListener {
                override fun onSucceed(content: String?) {

                }

            })
        }
    }
}

